00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef DEMEMORY_PRIV_HPP
00037 #define DEMEMORY_PRIV_HPP
00038
00039
00040 #include "deGlobalTypes.hpp"
00041 #include "Functions/Functions.hpp"
00042 #include "deMemory.hpp"
00043 #include "RedBlackTree.hpp"
00044
00045
00046
00047
00048 #ifdef _WIN32
00049
00050 #include <windows.h>
00051 #endif
00052
00053 class deMemoryManager : public IdeMemoryManager
00054 {
00055 public:
00056 deMemoryManager(char *ConfigFile);
00057 ~deMemoryManager();
00058
00059
00060 deBoolean IsInitialized();
00061
00062
00063 void * Malloc(unsigned int Size, MallocType Type, const char *File, long Line);
00064 void Free(void *Ptr, FreeType Type, const char *File, long Line);
00065 void * MemCpy(void *To, const void *From, unsigned int Size, const char *File, long Line);
00066 void * MemSet(void *To, int Value, unsigned int Size, const char *File, long Line);
00067
00068 private:
00069
00070 typedef struct AllocStruct
00071 {
00072 char * File;
00073 DWORD Line;
00074 IdeMemoryManager::MallocType AllocType;
00075 } AllocStruct;
00076
00077
00078 typedef struct RealAllocStruct
00079 {
00080 void * Ptr;
00081 DWORD Size;
00082 struct RealAllocStruct * Next;
00083 } RealAllocStruct;
00084
00085 deBoolean Initialized;
00086 RedBlackNode * RootFreeNode;
00087 RedBlackNode * RootAllocNode;
00088 RealAllocStruct * RootRealAllocList;
00089
00090
00091 void CheckMemoryLeaks();
00092 RedBlackNode *AllocRealMem(DWORD *Size);
00093 void ReleaseAllRealAllocMem();
00094 void OutputMemLeak(RedBlackNode *LeakAlloc);
00095 };
00096
00097
00098
00099 #define Round64k(Val) ((Val + 0x0000FFFF) & 0xFFFF0000)
00100 #define Round4(Val) ((Val + 3) & 0xFFFFFFFC)
00101
00102
00103
00104 #ifdef _WIN32
00105
00106
00107 static inline void *RealAlloc(DWORD *Size)
00108 {
00109
00110 *Size = Round64k(*Size);
00111
00112
00113 return VirtualAlloc(NULL, *Size, MEM_COMMIT, PAGE_READWRITE);
00114 }
00115
00116 static inline deBoolean RealFree(void *Ptr)
00117 {
00118
00119 return VirtualFree(Ptr, 0, MEM_RELEASE);
00120 }
00121
00122 #endif //_WIN32
00123
00124 #endif